/*
 ** Init_map2.c for Init_map2 in /home/dieng_e/zappy-2011/client_graphique/SDl
 **
 ** Made by el-hadji-malick-ndour dieng
 ** Login   <dieng_e@epitech.net>
 **
 ** Started on  Tue Jun 28 15:52:13 2011 el-hadji-malick-ndour dieng
** Last update Thu Jul  7 21:30:19 2011 el-hadji-malick-ndour dieng
 */

#include "header.h"
#include <SDL/SDL_events.h>

int Update_Map(SDL_Surface * screen)
{
    if (SDL_Flip(screen) == -1)
    {
        return (EXIT_FAILURE);
    }
    return EXIT_SUCCESS;
}

void Free_SDL_Surfaces(params * var)
{
/*
    SDL_FreeSurface(var->tmp);
*/
/*
    SDL_FreeSurface(var->message);
*/
    SDL_FreeSurface(var->screen);
/*
    TTF_CloseFont(var->font);

    TTF_Quit();
*/
    SDL_Quit();
}

int Draw_ttf(params *var)
{
    var->textColor.b = 255;
    var->textColor.g = 255;
    var->textColor.r = 255;
    var->font = TTF_OpenFont("./Fonts/CaslonBold.ttf", 28);

    if (var->font == NULL)
    {
        printf("error occured with TTF_OpenFont\n");
        exit(EXIT_FAILURE);
    }
    var->message = TTF_RenderText_Solid(var->font, "Un render en sdl_ttf", var->textColor);

    return (EXIT_SUCCESS);
}



void  Make_transparency(params *var)
{
    Uint32 color = SDL_MapRGB(var->message->format, 0, 0xFF, 0xFF);
    SDL_SetColorKey(var->message, SDL_RLEACCEL | SDL_SRCCOLORKEY, color);
}



void Sprite_function(_sprites *s_var, params *var)
{
/*
    On coupe la partie en haut à gauche (premier sprite)
*/
    s_var->clip[ 0 ].x = 0;
    s_var->clip[ 0 ].y = 0;
    s_var->clip[ 0 ].w = s_var->SHEET_WIDTH/2;
    s_var->clip[ 0 ].h = s_var->SHEET_HEIGHT/2;

/*
    On coupe la partie en haut à droite (second sprite)
*/
    s_var->clip[ 1 ].x = s_var->SHEET_WIDTH/2;
    s_var->clip[ 1 ].y = 0;
    s_var->clip[ 1 ].w = s_var->SHEET_WIDTH/2;
    s_var->clip[ 1 ].h = s_var->SHEET_HEIGHT/2;

/*
    On coupe la partie en bas à gauche (troisième sprite)
*/
    s_var->clip[ 2 ].x = 0;
    s_var->clip[ 2 ].y = s_var->SHEET_HEIGHT/2;
    s_var->clip[ 2 ].w = s_var->SHEET_WIDTH/2;
    s_var->clip[ 2 ].h = s_var->SHEET_HEIGHT/2;

/*
    On coupe la partie en bas à droite (quatrième sprite)
*/
    s_var->clip[ 3 ].x = s_var->SHEET_WIDTH/2;
    s_var->clip[ 3 ].y = s_var->SHEET_HEIGHT/2;
    s_var->clip[ 3 ].w = s_var->SHEET_WIDTH/2;
    s_var->clip[ 3 ].h = s_var->SHEET_HEIGHT/2;

     Blit_Surface( 0, 0, var->message, var->screen, &s_var->clip[ 0 ] );
     Blit_Surface( var->SCREEN_WIDTH-(s_var->SHEET_WIDTH/2), 0, var->message, var->screen, &s_var->clip[ 1 ] );
     Blit_Surface( 0, var->SCREEN_HEIGHT-(s_var->SHEET_HEIGHT/2), var->message, var->screen, &s_var->clip[ 2 ] );
     Blit_Surface( var->SCREEN_WIDTH-(s_var->SHEET_WIDTH/2), var->SCREEN_HEIGHT-(s_var->SHEET_HEIGHT/2), var->message, var->screen, &s_var->clip[ 3 ] );
}